package org.leyi.shop.util;

import lombok.extern.slf4j.Slf4j;
import org.leyi.shop.common.exception.BusinessException;
import org.leyi.shop.common.response.BaseResponse;
import org.leyi.shop.common.response.EnumResponse;

/**
 *
 * description:  TODO
 *<br> create 2024/5/4-23:40
 * @author  lenovo

 */
@Slf4j
public class BaseResponseUtils {
    public static <T> BaseResponse<T> success(T data)
    {
        log.info(EnumResponse.SUCCESS.getMessage());
        return new BaseResponse<T>(EnumResponse.SUCCESS,data);
    }
    public static <T> BaseResponse<T> success(T data,String message)
    {
        log.info(message);
        return new BaseResponse<T>(EnumResponse.SUCCESS,data,message);
    }
    public static  BaseResponse<String> success(String message)
    {
        log.info(message);
        return new BaseResponse<>(EnumResponse.SUCCESS,null,message);
    }

    public static  BaseResponse<String> error(EnumResponse enumResponse)
    {
        return new BaseResponse<>(enumResponse,null);
    }
    public static  BaseResponse<String> error(EnumResponse enumResponse,String message)
    {
        return new BaseResponse<>(enumResponse,null,message);
    }
    public static  BaseResponse<String> error(String message)
    {
        return new BaseResponse<>(EnumResponse.SYSTEM_ERR,null,message);
    }
    public static BaseResponse<String> error(BusinessException businessException)
    {
        return new BaseResponse<>(businessException.getCode(), null, businessException.getMessage(), businessException.getDescription());
    }
}
